package com.aaa.controller.xg;


import com.aaa.pojo.ResultBean;
import com.aaa.pojo.ResultDiv;
import com.aaa.pojo.ViewResultFpa;
import com.aaa.service.xg.ResultDivService;
import com.aaa.service.xg.ViewResultFpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/view")
public class ViewResultFpaController {

    @Autowired
    private ViewResultFpaService viewResultFpaService;

    @RequestMapping("/pagination")
    public ResultBean planFpa(String page, String limit){
        int count = viewResultFpaService.findCount();
        List<ViewResultFpa> all = viewResultFpaService.findAll(page, limit);

        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setCount(count);
        resultBean.setMsg("");
        resultBean.setData(all);
        return  resultBean;

    }

    /**
     * 查询
     * @return
     */
    @RequestMapping("/findGroup")
    public ResultBean findGroup(){
        List<ViewResultFpa> countById = viewResultFpaService.findCountById();
        ResultBean resultBean = new ResultBean();
        resultBean.setCount(0);
        resultBean.setData(countById);
        resultBean.setMsg("");
        return resultBean;
    }

    @RequestMapping("/findIf")
    public ResultBean findIf( String name,String testPlanId,String page,String limit){
        System.out.println(name);

        List<ViewResultFpa> viewResultFpaList = viewResultFpaService.findIf(name, testPlanId, page, limit);
        int ifCount = viewResultFpaService.findIfCount(name, testPlanId);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setCount(ifCount);
        resultBean.setData(viewResultFpaList);
        return resultBean;

    }

    @RequestMapping("/delete")
    public ResultBean delete(@RequestParam("idList") List<String> idList){

        System.out.println(idList);

        int delete = viewResultFpaService.delete(idList);
        System.out.println(delete);
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        return resultBean;
    }

    /**
     * 弹窗查看
     * @param testerId
     * @return
     */
    @RequestMapping("/findId")
    public ResultBean findById(int testerId){
        //System.out.println(testerId);
        ViewResultFpa fpaServiceById = viewResultFpaService.findById(testerId);
        ResultBean resultBean = new ResultBean();
        resultBean.setData(fpaServiceById);
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setCount(1);
        return resultBean;
    }

    @Autowired
    private ResultDivService resultDivService;

    @RequestMapping("/div")
    public ResultBean insertDiv(){
        List<ResultDiv> divs = resultDivService.findAll();
        ResultBean resultBean = new ResultBean();
        resultBean.setCode(0);
        resultBean.setMsg("");
        resultBean.setCount(4);
        resultBean.setData(divs);
        return resultBean;
    }

    /**
     * 报表结果统计
     */

    @RequestMapping("/findData")
    public  ResultBean findData() {
        Map<String, Integer> allData = viewResultFpaService.findAllData();

        int count = viewResultFpaService.findCount();
        ResultBean resultBean = new ResultBean();
        resultBean.setData(allData);
        resultBean.setMsg("");
        resultBean.setCode(0);
        resultBean.setCount(count);
        return resultBean;


    }
}
